package models

//使用vadalitor,在自定义错误信息方面，未找到错误信息定义的
// ex: 用户名（username） 不允许为空

// import (
// 	"fmt"
// 	"log"
// 	"net/http"

// 	"github.com/gin-gonic/gin"
// 	"github.com/go-playground/locales/en"
// 	"github.com/go-playground/locales/zh"
// 	ut "github.com/go-playground/universal-translator"
// 	"github.com/go-playground/validator/v10"
// 	zh_translations "github.com/go-playground/validator/v10/translations/zh"
// )

// func init() {
// 	fmt.Println("init login")
// }

// var trans ut.Translator

// type Login struct {
// 	Username string `form:"username" validate:"required"`
// 	Password string `form:"pwd"  validate:"required"`
// }

// func validLogin(c *gin.Context) {
// 	var form Login

// 	validate := validator.New()

// 	e := en.New()
// 	uniTrans := ut.New(e, e, zh.New())
// 	translator, _ := uniTrans.GetTranslator("zh")
// 	zh_translations.RegisterDefaultTranslations(validate, translator)

// 	if err := c.ShouldBind(&form); err != nil {
// 		c.JSON(http.StatusOK, gin.H{
// 			"msg": err.Error(),
// 		})
// 		return
// 	}

// 	if err := validate.Struct(form); err != nil {

// 		errs := err.(validator.ValidationErrors)
// 		sliceErrs := []string{}
// 		for _, e := range errs {
// 			// can translate each error one at a time.
// 			sliceErrs = append(sliceErrs, e.Translate(translator))
// 		}
// 		log.Printf("%#v", translator)
// 		c.JSON(http.StatusBadRequest, gin.H{
// 			// translate all error at once
// 			// returns a map with key = namespace & value = translated error
// 			// NOTICE: 2 errors are returned and you'll see something surprising
// 			// translations are i18n aware!!!!
// 			// eg. '10 characters' vs '1 character'
// 			"message":   errs.Translate(translator),
// 			"sliceErrs": sliceErrs,
// 		})
// 		return
// 	}

// 	if form.Username != "admin" || form.Password != "123" {
// 		c.Request.ParseForm()
// 		c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized", "form": form, "tp": c.Request.Form})
// 		return
// 	}

// 	c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})

// }
